package Title;

import java.io.*;
import java.util.ArrayList;

public class createFilesOfLeetCode {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new FileReader(new File("D:\\lc\\leetcode_names.txt")));
        String s;
        ArrayList<String> nameList = new ArrayList<>();
        while ((s = br.readLine()) != null) {
            String name = s.split("\\s+")[2];
            nameList.add(name);
        }
        br.close();
        System.out.println(nameList.toString());

        //创建文件
        String prefixPath = "D:\\lc\\";
        String suffixPath = ".java";
        for (int i = 0; i < nameList.size(); i++) {
            String name = nameList.get(i);
            String filename = prefixPath + name + suffixPath;
            String className = "public class " + name + "{";

            ArrayList<String> content = new ArrayList<>();
            content.add("package LeetCode;");

            content.add(className);
            content.add("    public static void main(String[] args) {");

            content.add("    }");

            content.add("    static class Solution {");
            content.add("    }");
            content.add("}");

            BufferedWriter bw1 = new BufferedWriter(new FileWriter(filename));
            for (int j = 0; j < content.size() - 1; j++) {
                bw1.write(content.get(j));
                bw1.newLine();
                bw1.newLine();
            }
            bw1.write(content.get(content.size() - 1));
            bw1.close();


        }


    }
}
